package com.cy.demo.controller;

import com.cy.demo.pojo.Product;
import com.cy.demo.service.IProductService;
import com.cy.demo.utils.jsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("products")
@RestController
public class ProductController extends BaseController{

    @Autowired
    private IProductService productService;

    @RequestMapping("/getHotList")
    public jsonResult<List<Product>> getHotList(){
        List<Product> data = productService.findHotList();
        return new jsonResult<List<Product>>(data,OK);
    }
    @RequestMapping("/getNewList")
    public jsonResult<List<Product>> getNewList(){
        List<Product> data = productService.findNewList();
        return new jsonResult<List<Product>>(data,OK);
    }

    @RequestMapping("/details/{id}")
    public jsonResult<Product> getDetails(@PathVariable int id) throws Exception {
        Product data = productService.findById(id);
        return new jsonResult<Product>(data,OK);
    }
}
